package com.punai.customer.controller;

import java.util.List;

import com.punai.common.core.domain.TreeBo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.enums.BusinessType;
import com.punai.customer.domain.CusSubpkChapter;
import com.punai.customer.service.ICusSubpkChapterService;
import com.punai.common.utils.poi.ExcelUtil;
import com.punai.common.core.page.TableDataInfo;

/**
 * 工序费用项章节Controller
 * 
 * @author zxw
 * @date 2022-12-04
 */
@RestController
@RequestMapping("/cus/subpkChapter")
public class CusSubpkChapterController extends BaseController
{
    @Autowired
    private ICusSubpkChapterService cusSubpkChapterService;

    /**
     * 查询工序费用项章节列表
     */
    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusSubpkChapter cusSubpkChapter)
    {
        startPage();
        List<CusSubpkChapter> list = cusSubpkChapterService.selectCusSubpkChapterList(cusSubpkChapter);
        return getDataTable(list);
    }

    /**
     * 获取工序费用项章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cusSubpkChapterService.selectCusSubpkChapterById(id));
    }

    /**
     * 新增工序费用项章节
     */
    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:add')")
    @Log(title = "工序费用项章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CusSubpkChapter cusSubpkChapter)
    {
        return toAjax(cusSubpkChapterService.insertCusSubpkChapter(cusSubpkChapter));
    }

    /**
     * 修改工序费用项章节
     */
    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:edit')")
    @Log(title = "工序费用项章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusSubpkChapter cusSubpkChapter)
    {
        return toAjax(cusSubpkChapterService.updateCusSubpkChapter(cusSubpkChapter));
    }

    /**
     * 删除工序费用项章节
     */
    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:remove')")
    @Log(title = "工序费用项章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cusSubpkChapterService.deleteCusSubpkChapterByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('cus:subpkChapter:list')")
    @GetMapping("/treeData")
    public AjaxResult list()
    {
        List<TreeBo> list = cusSubpkChapterService.treeData(getCompanyId());
        return AjaxResult.success(list);
    }

}
